<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<%@ include file="/mc/common/encodeURL.jsp" %>

<c:set var="pkg" value="${packageDetailView.map.pkg.map}"/>

<script language="JavaScript" src="<%= ctxPath %>/mt/js/userPopup.js"></script>

<script language="JavaScript">

  function confirmDelete(theForm) {
    var deleteMessage = '<bean-el:message key="bp.package.confirm.delete" bundle="bp.messages"/>';
    if ( confirm(deleteMessage)){
      theForm.action = '<html-el:rewrite page="/bp/packageDelete.do"/>';
      theForm.submit();
    }
    return false;
  }

  function doPackValidation(theForm) {
    window.name = "pmcMain";
    bparam = 'id=' + '<bean:write name="packageDetailView" property="pkg.id"/>';
    var str = encodeURL('bp/packageValidation.do', bparam);
    var qualifier = window.open(str, "packValidation", 
      'directories=no,height=550,width=750,left=0,top=0,resizable=yes,scrollbars=yes,location=no,menubar=no,status=no,toolbar=no');
    if (qualifier != null) {
        if (qualifier.opener == null)
          qualifier.opener = self;
        qualifier.focus();
    }
  }

  function doPackUserEditAction(theForm, participantNameIndex, participantValue) {
    var fieldName = 'participant[' + participantNameIndex + '].name';
    var field = findField(theForm, fieldName);
    if (field != null) {
      theForm.participantName.value = field.value;
      theForm.participantValue.value = participantValue;

      var timestamp = getTimeStamp();
      var parentFormName = "packageEditForm";
      var parentFieldName = "participantValue";
      var popupUrl = '<html-el:rewrite page="/mt/userSearchPopup.do"/>' + '?timestamp=' + timestamp +
                     '&parentFormName=' + parentFormName + 
                     '&parentFieldName=' + parentFieldName + 
                     '&userAlias=' + participantValue + '&executeSearch=true';

      var windowName = parentFormName + parentFieldName;
      var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
      var popupWindow = window.open(popupUrl, windowName, windowFeatures);
      if ( popupWindow != null) {
        if( popupWindow.opener == null) {
          popupWindow.opener = self;
        }
      }
      popupWindow.focus();
    }
    return true;
  }

  function setUserAlias(formName, fieldName, fieldValue) {
    var thisForm = document.forms[formName];
    var elements = thisForm.elements;
    var numElements = elements.length;
    var field;

    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        field = elements[elementIndex];
        break;
      }
    }
    field.value = fieldValue;

    thisForm.forwardPage.value = '<html-el:rewrite page="/bp/packageView.do"/>';
    thisForm.action = '<html-el:rewrite page="/bp/packageUserSave.do"/>'; 
    thisForm.submit();
  }

  
  function doPackGroupEditAction(theForm, participantNameIndex, participantValue) {
    var fieldName = 'participant[' + participantNameIndex + '].name';
    var field = findField(theForm, fieldName);
    if (field != null) {
      theForm.participantName.value = field.value;
      theForm.participantValue.value = participantValue;
      theForm.forwardPage.value = '<html-el:rewrite page="/bp/packageView.do"/>';
      theForm.action = '<html-el:rewrite page="/bp/packageGroupView.do"/>';
      theForm.submit();
    }
    return true;
  }
  
  function findField(theForm, fieldName) {
    var elements = theForm.elements;
    var numElements = elements.length;
    for (var elementIndex = 0; elementIndex < numElements; elementIndex++) {
      var elementName = elements[elementIndex].name;
      if (elementName == fieldName) {
        return elements[elementIndex];
      }
    }
    return null;
  }

</script>


<% 
  java.util.HashMap map = new java.util.HashMap();
  String packageId = request.getParameter("id"); 
  map.put("id", packageId);
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<c:set var="editImg">
<img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>">
</c:set>
<c:set var="individualImg">
<img src="<%= ctxPath %>/bp/images/icons/individual.gif" border="0" alt="<bean-el:message key="image.alt.individual" bundle="bp.messages"/>" title="<bean-el:message key="image.alt.individual" bundle="bp.messages"/>">
</c:set>
<c:set var="groupImg">
<img src="<%= ctxPath %>/bp/images/icons/group.gif" border="0" alt="<bean-el:message key="image.alt.group" bundle="bp.messages"/>" title="<bean-el:message key="image.alt.group" bundle="bp.messages"/>">
</c:set>

<!-- Zone 5 starts here.  -->
<html-el:form action="/bp/packageEdit.do">

<input type="hidden" name="id" value="<bean:write name="packageDetailView" property="pkg.id" />" />

<input type="hidden" name="cancelPage" value="/bp/packageView.do" />
<input type="hidden" name="forwardPage" value="/bp/packageUserSave.do" />
<input type="hidden" name="participantName"/>
<input type="hidden" name="participantValue"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.package.contentArea" bundle="bp.messages"/>">
  <tr>
    <td valign="top" width="100%">
		    
      <div class="pageTitle">
        <c:out value="${pkg.name}"/>
      </div> 
			
      <!-- pageTab -->
      <div class="errorMessage"><html-el:errors bundle="bp.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>
      <!-- end of PageTab -->
			
      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="bp.package.detail" bundle="bp.messages"/></span>
        <span class="right">
          <logic:equal name="packageDetailView" property="canEdit" value="true">
            <input type="button" name="validatePack" class="titleButton"
              onclick="doPackValidation(this.form);" value='<bean-el:message key="button.userResolution" bundle="bp.messages"/>'>
            <logic:equal name="packageDetailView" property="pkg.deployStatus" value="1">
              <html-el:submit styleClass="titleButton">
                <bean-el:message key="button.edit" bundle="bp.messages"/>
              </html-el:submit>
            </logic:equal>
            <logic:equal name="packageDetailView" property="pkg.deployStatus" value="3">
              <html-el:submit styleClass="titleButton">
                <bean-el:message key="button.edit" bundle="bp.messages"/>
              </html-el:submit>
            </logic:equal>
          </logic:equal>
        </span>
      </div> 
			
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.package.contentArea" bundle="bp.messages"/>">
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageName" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <c:out value="${pkg.name}"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageDescription" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <c:out value="${pkg.description}"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageStatus" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <c:out value="${pkg.displayStatusString}"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.createdDate" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <bean:write name="pkg" property="creationTime" formatKey="format.datetime.long"  bundle="mc.messages"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.lastModifiedDate" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <bean:write name="pkg" property="lastModTime"  formatKey="format.datetime.long" bundle="mc.messages"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.deployer" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <c:out value="${pkg.deployer}"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageVersion" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
	    <c:out value="${pkg.userInputVersion}"/>
          </td>
        </tr>
      </table>
			
      <br>
      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="bp.package.participantList" bundle="bp.messages"/></span>
        <span class="right">&nbsp;</span>
      </div> 
  
      <!--end page title area here-->
      <div class="pageInstructions">(*) <bean-el:message key="bp.package.detail.instruction" bundle="bp.messages"/></div>
			
      <!-- Start List here -->
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Name" align="left"><bean-el:message key="bp.package.participantName" bundle="bp.messages"/></th>
          <th id="Description" align="left"><bean-el:message key="bp.package.participantDescription" bundle="bp.messages"/></th>
          <th id="Identities" align="left"><bean-el:message key="bp.package.participantIdentities" bundle="bp.messages"/></th>
          <logic:equal name="packageDetailView" property="canEditActor" value="true">
            <th id="Actions" align="left" nowrap><bean-el:message key="header.actions" bundle="bp.messages"/></th>
          </logic:equal>
        </tr>

         <logic:iterate id="participant" name="packageDetailView" property="participants" indexId="i">

           <logic:notEqual name="participant" property="name" value="LaunchUser">
           <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">

             <td headers="Name">
               <logic:equal name="participant" property="type" value="0">
                 <c:out value='${individualImg}' escapeXml="false"/>
               </logic:equal>
               <logic:notEqual name="participant" property="type" value="0">
                 <c:out value='${groupImg}' escapeXml="false"/>
               </logic:notEqual>
               &nbsp;<c:out value="${participant.map.name}"/>
             </td>
             <td headers="Description">
               <c:out value="${participant.map.description}"/>&nbsp;
             </td>
             <td headers="Identities">
               <logic:equal name="participant" property="valueValid" value="0">
                 *
               </logic:equal>
               <c:out value="${participant.map.value}"/>
             </td>
             <logic:equal name="packageDetailView" property="canEditActor" value="true">
               <td nowrap align="left" headers="Actions">
                 <html-el:hidden name='participant' property='name' indexed='true'/>
                 <logic:equal name="participant" property="type" value="0">
                   <a href="#" onclick='javascript:doPackUserEditAction(document.packageEditForm, <%=i%>, "<c:out value="${participant.map.value}"/>")'><c:out value='${editImg}' escapeXml="false"/></a>
                 </logic:equal>
                 <logic:notEqual name="participant" property="type" value="0">
                   <a href="#" onclick='javascript:doPackGroupEditAction(document.packageEditForm, <%=i%>, "<c:out value="${participant.map.value}"/>")'><c:out value='${editImg}' escapeXml="false"/></a>
                 </logic:notEqual>
               </td>
             </logic:equal>
            </tr>
           </logic:notEqual>
         </logic:iterate>

      </table>

      <!--end list here-->
			  
    </td>
  </tr>
</table>

</html-el:form>

<!--end zone 5 content here -->

